-- 布朗陶之剑
local bulangtaozhijian = fk.CreateSkill {
    name = "mcdh_bulangtaozhijian",
}

bulangtaozhijian:addEffect(fk.TargetSpecified,{
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 and
                #AimGroup:getAllTargets(data.tos) == 1 and target == player and data.card.is_damage_card
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local card_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
        card_event.bulangtaozhijian = true
        local card_targets = AimGroup:getAllTargets(data.tos)[1]
        local targets = room:getOtherPlayers(player)
        for _, p in ipairs(targets) do
            if room:getPlayerById(card_targets):isNude() then
                break
            end
            if p ~= room:getPlayerById(card_targets) then
                local dis = room:askForDiscard(p, 1, 1, true, self.name, true, ".",
                        "#mcdh_bulangtaozhijian-discard:" .. card_targets)
                if #dis ~= 0 then
                    local id = room:askForCardChosen(p, room:getPlayerById(card_targets), "he", self.name)
                    room:throwCard(id, self.name, room:getPlayerById(card_targets), player)
                    room:setPlayerMark(p, "#mcdh_bulangtaozhijia-turn", 1)
                end
            elseif room:getPlayerById(card_targets):getHandcardNum() >= 2 then
                local dis = room:askForDiscard(p, 1, 1, true, self.name, true, ".",
                        "#mcdh_bulangtaozhijian-discard:" .. card_targets)
                if #dis ~= 0 then
                    local id = room:askForCardChosen(p, room:getPlayerById(card_targets), "he", self.name)
                    room:throwCard(id, self.name, room:getPlayerById(card_targets), player)
                    room:setPlayerMark(p, "#mcdh_bulangtaozhijia-turn", 1)
                end
            end
        end
    end
})

return bulangtaozhijian